import sys
sys.path.append("../")
from frameworks.utils.FetchHttp import *
import time
import requests

class BaiKuaiController():
    def __init__(self,args):
        self.args = args

    def run(self):
        if self.args["func"] == "getToday":
            return self.getToday()

    def getToday(self):
        alldata = []

        http = FetchHttp()
        current_milli_time = lambda: int(round(time.time() * 1000))
        url = "http://60.push2.eastmoney.com/api/qt/clist/get?pn=1" \
              "&pz=20&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&wbp2u=|0|0|0|web&fid=f3" \
              "&fs=m:90+t:3+f:!50&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f33,f11,f62," \
              "f128,f136,f115,f152,f124,f107,f104,f105,f140,f141,f207,f208,f209,f222&_=" + str(current_milli_time())

        #json = http.craw(url)
        json = requests.get(url).json()
        for i in range(0, 10):
            option = {"name": json["data"]["diff"][i]["f14"], "real_value": str(json["data"]["diff"][i]["f3"])+"%", "value": json["data"]["diff"][i]["f3"]+10}
            alldata.append(option)

        url = "http://60.push2.eastmoney.com/api/qt/clist/get?pn=1" \
              "&pz=20&po=0&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&wbp2u=|0|0|0|web&fid=f3" \
              "&fs=m:90+t:3+f:!50&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f33,f11,f62," \
              "f128,f136,f115,f152,f124,f107,f104,f105,f140,f141,f207,f208,f209,f222&_=" + str(current_milli_time())

        json = requests.get(url).json()
        for i in range(0, 10):
            option = {"name": json["data"]["diff"][i]["f14"], "real_value": str(json["data"]["diff"][i]["f3"])+"%", "value": json["data"]["diff"][i]["f3"]+10}
            alldata.append(option)

        return alldata
